package Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets// ActionScript file
{
	import Classes.CustomClasses.CallbackTimer;
	import Classes.CustomEvents.CustomEvent;
	import Classes.GameDatas.GD_AllFriends;
	import Classes.GameDatas.GD_Building_Sundry;
	import Classes.GameDatas.GD_Character;
	import Classes.GameDatas.GD_HiredFriend;
	import Classes.GameDatas.GD_MapGrid;
	import Classes.GameDatas.GD_Player;
	import Classes.GameDatas.GD_Weapon;
	import Classes.GameDatas.GD_Zombie;
	import Classes.GameDatas.GameData;
	import Classes.GameUtils.GD_deal;
	import Classes.GameUtils.GU_BarPathFinding;
	import Classes.GameUtils.GU_Sound;
	import Classes.GameUtils.GU_dealBgSound;
	import Classes.GameUtils.LinkAction.LinkAction;
	import Classes.GameViews.GV_Map;
	import Classes.GameViews.ViewCartoonTargets.VCT_PaperMan;
	import Classes.GameViews.ViewDisplayers.MapTargets.MT_Building_Sundry;
	import Classes.GameViews.ViewDisplayers.MapTargets.MT_HavenWall;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MapNPCs.MN_SickMan;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MapNPCs.MN_Zombie;
	import Classes.GameViews.ViewDisplayers.MapTargets.MapTarget;
	import Classes.GameViews.ViewPanels.VP_BubbleUp;
	import Classes.GameViews.ViewPanels.VP_errorPanel;
	import Classes.Interfaces.I_ControlTarget;
	import Classes.Interfaces.I_Observer;
	import Classes.Managers.M_Communication;
	import Classes.staticinfo.Language;
	import Classes.staticinfo.PlatformInfo;
	import Classes.staticinfo.StaticInfo;
	
	import MV_BMP.MovieClip_BMP;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.system.ApplicationDomain;
	import flash.system.System;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	/**
	 *角色类 
	 * @author 葛增文
	 * 
	 */	
	public class MMT_Character extends MapMoveTarget implements I_Observer,I_ControlTarget
	{
		public static const BEHITTEDCOOLDOWN:Number=60;/*被击所需冷却时间*/
		public static const CUREROUND:int=4;/*治愈周期*/
		private static var _instance:MMT_Character;/*静态引用*/
		private var _cureCount:int;/*治愈计数*/
		private var _findingAry:Array;/*寻径数组*/
		private var _nowMoveAry:Array;/*当前移动路径点数组*/
		private var _actTarget:MapTarget;/*目标对象*/
		private var _paperMan:VCT_PaperMan;/*角色纸娃娃*/
		private var _faceDir:int=1;/*面朝方向*/
		private var _actionName:String="";/*需要播放的动画名*/
		private var _beHittedCoolDown:int;/*被击冷却*/
		private var _isControl:Boolean;/*被玩家控制标记*/
		private var _infectionState:Boolean;/*当前感染状态 false:正常 true:僵尸*/
		private var _lifeBar:Sprite;/*生命槽*/
		private var _cureState:Boolean;/*当前治疗状态 false:不在治疗期 true:治疗期*/
		
		private var linkAction:LinkAction;
		
		public function MMT_Character(gd:GameData):void
		{
			super(gd);
			_instance=this;
			this.init();
		}
		
		private function init():void
		{
			this.linkAction		=	new LinkAction(this);
			
			this._findingAry=new Array;
			this._nowMoveAry=new Array;
			this._lifeBar=new (ApplicationDomain.currentDomain.getDefinition("PlayerLifePanel_v") as Class);
			this._lifeBar.scaleX=0.5;
			this._lifeBar.scaleY=0.5;
			this.addChild(this.lifeBar);
			this.moveConditionsAry=["没有建筑"];
			
			if(!this.characterData.controlEnabled)
			{
				this.lifeBar["setBgVisabe"](true,this.characterData.gd_characterPlay.playerName);
				controlJianTouVisable(false);
				this.lifeBar["setActionVisable"](false);
				this.lifeBar["setLifeVisable"](false);
				this.characterData.addObserver("weaponchange",this);
			}else{
				this.lifeBar["setBgVisabe"](false,"");
				this.lifeBar["setLifeVisable"](true);
				
				//				this.characterData.life=1;
				this.showLife();
				this.characterData.addObserver("life",this);
				this.characterData.addObserver("weaponchange",this);
				this.characterData.addObserver("palySpeed",this);
				this.showPlaySpeed();
				if(this.characterData.characterState==1)
				{
					this.characterData.addObserver("friendAct",this);
					controlJianTouVisable(false);
					this.lifeBar["setActionVisable"](true);
					this.showAct();
				}else{
					this._lifeBar.y+=10;
					controlJianTouVisable(true);
					this.lifeBar["setActionVisable"](false);
				}
			}
			this.addListener();
		}
		
		/**
		 * 控制选中对象头顶箭头标记 
		 * @param isVisabel
		 */		
		public function controlJianTouVisable(isVisabel:Boolean):void
		{
			var oldState:Boolean=(this.lifeBar["playerControlerFlag"] as DisplayObject).visible;
			(this.lifeBar["playerControlerFlag"] as DisplayObject).visible=isVisabel;
			if(oldState!=isVisabel && oldState==false)
			{
				GU_dealBgSound.instance.zhuiJiZombieNum=0;
			}
			//根据选中的人物地点来控制背景音乐的播放
			if(isVisabel)
			{
				if(this.mapGrid && (this.mapGrid.isHaven || this.mapGrid.isWall))
				{
					GU_dealBgSound.instance.turnMusicByCharacter=0;
				}
				if(this.mapGrid && !this.mapGrid.isHaven && !this.mapGrid.isWall)
				{
					GU_dealBgSound.instance.turnMusicByCharacter=1;
				}
			}
		}
		
		private var oldWeapon:String;
		public function setBaseCartoonsType(type:String):void
		{
			this._paperMan=new VCT_PaperMan(type);
			this.paperMan.playAction("leftUp","stand");
			this.addChildAt(this.paperMan,0);
			this.paperMan.x=10;
			this.paperMan.y=5;
			if(this.characterData.gd_characterPlay.playerSex=="0")
			{
				this.paperMan.dress("nvhai_mz");
				this.paperMan.dress("nvhai_yf");
				this.paperMan.dress("nvhai_kz");
				this.paperMan.dress("nvhai_xz");
			}else{
				this.paperMan.dress("nanhai_mz");
				this.paperMan.dress("nanhai_yf");
				this.paperMan.dress("nanhai_kz");
				this.paperMan.dress("nanhai_xz");
			}
		}
		
		private function addListener():void
		{
			this.addEventListener(CustomEvent.CARTOONPLAYOVER,cartoonOverHandler);
		}
		
		private function removeListener():void
		{
			this.removeEventListener(CustomEvent.CARTOONPLAYOVER,cartoonOverHandler);
		}
		
		/**
		 *对象被点击 
		 * @param e
		 * 
		 */		
		override public function beClicked(e:MouseEvent):void
		{
			if(!this.characterData.controlEnabled)
			{
				if((this.characterData.gd_characterPlay as GD_HiredFriend) && (this.characterData.gd_characterPlay as GD_HiredFriend).pf!=PlatformInfo.instance.pf)
				{
					VP_errorPanel.instance.setErrorMessage(Language.diffenctPlat);
					VP_errorPanel.instance.enterFrame();
				}
				return;
			}
			super.beClicked(e);
			var mmtObj:Object=GV_Map.instance.controlTargetObj;
			for each(var mmtView:MMT_Character in mmtObj)
			{
				mmtView.isControl=false;
				mmtView.controlJianTouVisable(false);
			}
			this.isControl=true;
			GV_Map.instance.controlTarget=this;
			this.controlJianTouVisable(true);
			
			//			super.beClicked(null);
		}
		
		public function touchObserve(observeType:String):void
		{
			switch(observeType)
			{
				case "life":
					this.showLife();
					break;
				case "weaponchange":
					this.changeWeapon();
					break;
				case "friendAct":
					this.showAct();
					break;
				case "palySpeed":
					this.showPlaySpeed();
					break;
			}
		}
		
		/**
		 *  更换武器 
		 */		
		private function changeWeapon():void
		{
			if(null!=this.oldWeapon && "0"!=this.oldWeapon && this.oldWeapon!="")
			{
				this.paperMan.undress(this.oldWeapon);
			}
			this.paperMan.dress(this.characterData.currentOwnWeapon);
			this.oldWeapon=this.characterData.currentOwnWeapon;
		}
		
		private function showAct():void
		{
			if(this.characterData.gd_characterPlay)
			{
				this.lifeBar["setAct"](this.characterData.gd_characterPlay.actPoint,5)
			}
		}
		
		private function showLife():void
		{
			if(this.characterData.life==this.characterData.lifeMax)this.finishCure();
			this.lifeBar["setLife"](this.characterData.life,this.characterData.lifeMax)
			if(this.characterData.life<1)this.turnToZombie();
		}
		
		/**
		 *动画播放完的处理 
		 * @param e
		 * 
		 */		
		private function cartoonOverHandler(e:CustomEvent):void
		{
			switch(e.msgStr)
			{
				case "attack":
					break;
				case "beHitted":
					break;
				case "heal":
					break;
				case "collect":
					break;
			}
			this.actionLocked=false;
			this.actionInterrupt();
		}
		
		/**
		 *更新 
		 * 
		 */		
		override public function update():void
		{
			if(this.cureState)
			{
				this.cureCount+=1;
				if(this.cureCount==this.cureRound)
				{
					var nowPercent:int=int(this.lifeBar["getLifePercent"]);
					if(nowPercent!=100)
					{
						nowPercent+=1;
						this.lifeBar["setLifePercent"](nowPercent);
						if(nowPercent==100)
						{
							this.sendCure();
						}
					}
					this.cureCount=0;
				}
			}
			
			if(this.beHittedCoolDown)
			{
				this.beHittedCoolDown-=1;
			}
			if(this.actionName!="")
			{
				if(this.infectionState)
				{
					this.actionName="infection_"+this.actionName;
				}
				
				this.paperMan.playAction(String(this.transformDir(this.faceDir)),this.actionName);
				
				this.actionName="";
			}
			super.update();
			

//			trace(this.actionLocked,this.moveDir);
			if(!this.moveDir && !this.actionLocked){							//空闲时
						this.linkAction.update();
				/*
				if(this.autoRepairWall)
				this.setAutoTarget();
				*/
			}
		}
		
		/**
		 *变僵尸 
		 * 
		 */		
		public function turnToZombie():void
		{
			
			this.infectionState=true;
			this.actionLocked=false;
			this.actionInterrupt();
			this.setState(10002001,true,500);
			//			VP_DiePanel.instance.openPanel();			//死亡面板
		}
		
		/**
		 *变人类 
		 * 
		 */		
		public function turnToHunman():void
		{
			this.infectionState=false;
			this.actionInterrupt();
			this.setState(10002001,true,500);
		}
		
		/**
		 *下一步行动 
		 * 
		 */		
		override protected function nextStep():void
		{
			if(this.actTarget && this.actCheck())
			{
				if(this.characterData.characterState==3)
				{
					//掉落奖励  
					GD_AllFriends.instance.playFriendOver(this.characterData);
				}
			}
			else
			{
				this.nextMove();
			}
		}
		
		/**
		 *行动判定 
		 * @return 行为是否完成
		 * 
		 */		
		private function actCheck():Boolean
		{
			if(!this.actTarget.actionEnabled)
			{
				return true;
			}
			else if(this.actTarget is MN_Zombie)
			{
				return this.actAtt();
			}
			else if(this.actTarget is MN_SickMan)
			{
				return this.actCure();
			}
			else if(this.actTarget is MT_HavenWall)
			{
				return this.actRepair();
			}
			else if(this.actTarget is MT_Building_Sundry)
			{
				return this.actRemove();
			}
			return false
		}
		
		/**
		 * 行动力不足 
		 * @return 
		 */		
		private function notEnoughtAct():Boolean
		{
			var flag:Boolean=false;
			var currentAct:Number=this.characterData.characterState==2?GD_Player.instance.friendAct:this.characterData.gd_characterPlay.actPoint;
			if(currentAct<1)
			{
				VP_errorPanel.instance.setErrorMessage(Language.notEnoughAct);
				VP_errorPanel.instance.enterFrame();
				flag=true;
				GU_Sound.instance.playCommSound("System_Prompt");
			}
			return flag;
		}
		
		/**
		 *攻击行为
		 * @param target 目标僵尸 
		 * @return 行为是否完成
		 * 
		 */		
		private function actAtt():Boolean
		{
			var attZombie:MN_Zombie=this.actTarget as MN_Zombie;
			var dis:Number=GV_Map.instance.getFindingPriceBetweenTwoPoints(this.mapGrid.coordinatePoint,attZombie.mapGrid.coordinatePoint);
			var attResult:int=attZombie.zombieData.checkAttackResult(this.characterData.gd_characterPlay.attType);
			//回放好友在我家打僵尸
			if(this.characterData.characterState==3 && dis<=this.characterData.gd_characterPlay.attRange && attResult)
			{
				var playTargerObj:MapTarget=(GV_Map.instance.controlTarget as MMT_Character).actTarget;
				if(playTargerObj as GD_Zombie && (playTargerObj as GD_Zombie).serverID==attZombie.zombieData.serverID)
				{
					GD_AllFriends.instance.callZombieFun(this);
					return false;
				}
				this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
				this.actionLocked=true;
				this.actionName=this.characterData.gd_characterPlay.attactType;
				attZombie.actBeHitted();
				return true;
			}else if(dis<=this.characterData.gd_characterPlay.attRange && attResult && !this.notEnoughtAct())
			{
				//判断自己的子弹数目
				if(this.characterData.gd_characterPlay.playerID==GD_Player.instance.playerID && GD_Player.instance.getCurrentWeaponByType(Number(GD_Player.instance.currentWeapon)).itemNumber==0)
				{
					VP_errorPanel.instance.setErrorMessage(Language.notEnoughWeapon);
					VP_errorPanel.instance.enterFrame();
					GU_Sound.instance.playCommSound("System_Prompt");
					return false;	
				}
				
				
				var soundName:String;
				if(this.characterData.characterState==1){
					soundName	=	GD_Weapon.itemConfigDatasObj[((this.gameData as GD_Character).gd_characterPlay as GD_HiredFriend).weaponId].zt_sound_name;
					//				soundName	=	GU_Sound.instance.getMusicNameByWopenId( ((this.gameData as GD_Character).gd_characterPlay as GD_HiredFriend).weaponId );
				}
				else{
					var wid:Number	= Number(this.characterData.gd_characterPlay.currentWeapon);
					soundName	=	GD_Player.instance.getCurrentWeaponByType(wid)._singleWeaponItem.zt_sound_name;
					//				soundName	=	GU_Sound.instance.getMusicNameByWopenId( GD_Player.instance.getCurrentWeaponByType(wid).weaponId );
					
					
					var weaponId:Number=Number(this.characterData.gd_characterPlay.currentWeapon);
					//					喷火
					var r:Number	=	Math.atan2(attZombie.y-this.y, attZombie.x-this.x) * 180/Math.PI;
					//					trace(GD_Weapon.getWeaponInfoById(weaponId).zt_act_tx, GD_Weapon.getWeaponInfoById(weaponId).zt_beact_tx);
					if(GD_Weapon.getWeaponInfoById(weaponId).zt_act_tx!=0)
						this.setState(GD_Weapon.getWeaponInfoById(weaponId).zt_act_tx,true,500,r+30);		//攻击特效旋转
					
					
					//被攻击
					
//					trace("面朝",this._faceDir,this.getFaceTargetGridDir(this.actTarget.mapGrid));
//					var jx:uint	= Math.abs(r)>=90?1:0;
					
					var jx:uint;
					var fdir:uint	=	this.getFaceTargetGridDir(this.actTarget.mapGrid);
					if(fdir==2 || fdir==8)jx=1;
					else jx=0;
					if(GD_Weapon.getWeaponInfoById(weaponId).zt_beact_tx!=0)							
					{
						var tm:Timer	=	new Timer(300,1);
						tm.addEventListener(TimerEvent.TIMER, function(e:Event):void{
							attZombie.setStates(GD_Weapon.getWeaponInfoById(weaponId).zt_beact_tx,true,1000,jx);
							
							//							attZombie.setState(10004004,true,1000,jx);
						});
						tm.start();
					}
			
				}
				
				if("" != soundName)
					GU_Sound.instance.playCommSound(soundName);
				
				this.sendMsg(400,sendAtt,[this.actTarget]);
				this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
				this.actionLocked=true;
				this.actionName=this.characterData.gd_characterPlay.attactType;
				attZombie.actBeHitted();
				return true;
			}
			return false;
		}
		
		private var testSprite:Sprite;
		
		/**
		 *修理行为 
		 * @param target 目标墙壁
		 * @return 行为是否完成
		 * 
		 */		
		private function actRepair():Boolean
		{
			var wallView:MT_HavenWall=this.actTarget as MT_HavenWall;
			var dis:Number=GV_Map.instance.getFindingPriceBetweenTwoPoints(this.mapGrid.coordinatePoint,wallView.mapGrid.coordinatePoint);
			//回放好友在我家修理围墙
			if(this.characterData.characterState==3 && dis<=this.characterData.gd_characterPlay.repairRange)
			{
				this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
				this.actionLocked=true;
				this.actionName="heal";
				wallView.setState(10000003,true,1000);
				GU_Sound.instance.playCommSound("Body_Repair");
				
				return true;
			}else if(dis<=this.characterData.gd_characterPlay.repairRange && !this.notEnoughtAct())
			{
				this.sendMsg(400,sendRepair,[this.actTarget]);
				this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
				this.actionLocked=true;
				this.actionName="heal";
				wallView.setState(10000003,true,1000);
				GU_Sound.instance.playCommSound("Body_Repair");
				
				return true;
			}
			return false
		}
		
		
		/**
		 * 铲除杂物 
		 * @return 
		 */		
		private function actRemove():Boolean
		{
			var sundryView:MT_Building_Sundry=this.actTarget as MT_Building_Sundry;
			if(this.actTarget.mapGrid==null)return true;
			var oldP:Point=sundryView.mapGrid.coordinatePoint;
			var newP:Point=new Point(oldP.x+sundryView.buildingSundryData.size/2,oldP.y+sundryView.buildingSundryData.size/2);
			var dis:Number=GV_Map.instance.getFindingPriceBetweenTwoPoints(this.mapGrid.coordinatePoint,newP);
			var repairRange:int=sundryView.buildingSundryData.size>=8?this.characterData.gd_characterPlay.repairRange:2;
			var range:Number=repairRange+sundryView.buildingSundryData.size/2;
			
			//回放好友在我家清杂物
			if(this.characterData.characterState==3 && dis<=range)
			{
				var playTargerObj:MapTarget=(GV_Map.instance.controlTarget as MMT_Character).actTarget;
				if(playTargerObj as GD_Building_Sundry && (playTargerObj as GD_Building_Sundry).serverID==sundryView.buildingSundryData.serverID)
				{
					GD_AllFriends.instance.callSundryFun(this);
					return false;
				}
				this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
				this.actionLocked=true;
				this.actionName="collect";
				return true;
			}else if(dis<=range && !this.notEnoughtAct())
			{
				if(GD_deal.instance.getStr(sundryView.buildingSundryData.sundryType)==StaticInfo.NPC_SUNDRY_TYPE)
				{
					this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
					this.actionLocked=true;
					var vp_bubbleUp:VP_BubbleUp=new VP_BubbleUp();
					vp_bubbleUp.scaleX=0.6;
					vp_bubbleUp.scaleY=0.6;
					vp_bubbleUp.setPopTxts(Language.sundryPop);
					sundryView.addEffect(vp_bubbleUp,playOver);
				}else{
					this.sendMsg(400,sendRemove,[this.actTarget]);
					this.faceDir=this.getFaceTargetGridDir(this.actTarget.mapGrid);
					this.actionLocked=true;
					this.actionName="collect";
				}
				GU_Sound.instance.playCommSound("Body_Dig");
				return true;
			}
			return false;		
		}
		
		private function playOver():void
		{
			this.actionLocked=false;
			this.sendMsg(50,sendRemove,[this.actTarget]);
		}
		
		/**
		 * 发送铲除杂物的行为 
		 * @param parsAry
		 */		
		private function sendRemove(parsAry:Array):void
		{
			var sundryView:MT_Building_Sundry=parsAry[0] as MT_Building_Sundry;
			if(null==sundryView.buildingSundryData)return;
			if(this.characterData.characterState==0)
			{
				M_Communication.instance.send(12004,{sundryID:sundryView.buildingSundryData.serverID});
			}else if(this.characterData.characterState==1){
				M_Communication.instance.send(127003,{sundryID:sundryView.buildingSundryData.serverID,friendID:this.characterData.characterId});
			}else if(this.characterData.characterState==2){
				M_Communication.instance.send(128002,{friendID:GD_AllFriends.instance.currentVisableFriendId,sundryID:sundryView.buildingSundryData.serverID,
					sundryNowLife:sundryView.buildingData.currentlife});
			}
		}
		
		/**
		 * 发送修理围墙的命令 
		 * @param parsAry  parsAry[0] 围墙视图对象-MT_HavenWall
		 * 
		 */		
		public function sendRepair(parsAry:Array):void
		{
			var wallView:MT_HavenWall=parsAry[0] as MT_HavenWall;
			if(this.characterData.characterState==0)
			{
				M_Communication.instance.send(12003,{wallSerial:wallView.wallData.wallSerial});
			}else if(this.characterData.characterState==1){
				M_Communication.instance.send(127004,{wallSerial:wallView.wallData.wallSerial,friendID:this.characterData.characterId});
			}else if(this.characterData.characterState==2){
				M_Communication.instance.send(128001,{friendID:GD_AllFriends.instance.currentVisableFriendId,wallSerial:wallView.wallData.wallSerial,
					wallNowLife:wallView.wallData.dur});
			}
		}
		
		
		/**
		 *治疗行为
		 * @param target 目标病人 
		 * @return 行为是否完成
		 */		
		private function actCure():Boolean
		{
			return false
		}
		
		
		/**
		 *被攻击行为 
		 * 
		 */		
		public function actBeHitted(target:MN_Zombie):void
		{
			this.sendMsg(400,sendBeHitted,[target]);
			this.actionLocked=true;
			this.actionName="beHitted";
			this.beHittedCoolDown=BEHITTEDCOOLDOWN;
		}
		
		/**
		 *获得面向对象地图格的方向值 
		 * @param targetGrid 对象地图格
		 * @return 
		 * 
		 */		
		private function getFaceTargetGridDir(targetGrid:GD_MapGrid):int
		{
			var xDis:int=targetGrid.atx-this.mapGrid.atx;
			var yDis:int=targetGrid.aty-this.mapGrid.aty;
			if(Math.abs(yDis)>Math.abs(xDis))
			{
				if(yDis>0)
				{
					return 8;						//下
				}
				else
				{
					return 4;						//上
				}
			}
			else
			{
				if(xDis>0)
				{
					return 6;						//右
				}
				else
				{	
					return 2;						//左
				}
			}
		}
		
		/**
		 *延迟发送消息 
		 * 
		 */		
		private function sendMsg(delayTime:Number,func:Function,funcParsAry:Array):void
		{
			var timer:CallbackTimer=new CallbackTimer(delayTime,func,funcParsAry);
			timer.start();
			timer.addEventListener(TimerEvent.TIMER,sendNow);
		}
		
		/**
		 *发送消息时间计数到达
		 * @param e
		 * 
		 */		
		private function sendNow(e:TimerEvent):void
		{
			var timer:CallbackTimer=e.target as CallbackTimer; 
			timer.stop();
			timer.removeEventListener(TimerEvent.TIMER,sendNow);
			timer.callback(timer.callbackParsAry);
		}
		
		/**
		 *攻击消息发送 (打怪)
		 * @param e
		 * 
		 */		
		private function sendAtt(parsAry:Array):void
		{
			var beHittedZombie:MN_Zombie=parsAry[0] as MN_Zombie;
			if(this.characterData.characterState==0)
			{
				var msgContent:Object={zombieID:beHittedZombie.zombieData.serverID,weaponType:GD_Player.instance.currentWeapon};
				M_Communication.instance.send(12000,msgContent);
			}else if(this.characterData.characterState==1){
				var friendMsg:Object={zombieID:beHittedZombie.zombieData.serverID,friendID:this.characterData.characterId};
				M_Communication.instance.send(127005,friendMsg);
			}else if(this.characterData.characterState==2){
				M_Communication.instance.send(128000,{friendID:GD_AllFriends.instance.currentVisableFriendId,zombieID:beHittedZombie.zombieData.serverID,weaponType:GD_Player.instance.currentWeapon,
					zombieNowLife:beHittedZombie.zombieData.life});
			}
		}
		
		/**
		 *被攻击消息发送 
		 * @param par
		 * 
		 */		
		private function sendBeHitted(parsAry:Array):void
		{
			var attZombie:MN_Zombie=parsAry[0] as MN_Zombie;
			if(null ==attZombie || null==attZombie.zombieData)
			{
				return;
			}
			if(this.characterData.characterState==0)
			{
				var msgContent:Object={zombieID:attZombie.zombieData.serverID};
				M_Communication.instance.send(12005,msgContent);
			}else if(this.characterData.characterState==1){
				var friendMsg:Object={zombieID:attZombie.zombieData.serverID,friendID:this.characterData.characterId};
				M_Communication.instance.send(127006,friendMsg);
			}else if(this.characterData.characterState==2)
			{
				var goToFriend:Object={zombieID:attZombie.zombieData.serverID,friendID:GD_AllFriends.instance.currentVisableFriendId};
				M_Communication.instance.send(12005,goToFriend);
			}
		}
		
		/**
		 *治愈消息发送 
		 * 
		 */		
		private function sendCure():void
		{
			if(this.characterData.characterState==0 || this.characterData.characterState==2)
			{
				M_Communication.instance.send(12009);
			}else if(this.characterData.characterState==1){
				M_Communication.instance.send(127007,{friendID:this.characterData.characterId});
			}
		}
		
		/**
		 *播放当前事件 
		 * 
		 */		
		private function playNowState():void
		{
			if(this.moveDir)
			{
				this.faceDir=this.moveDir;
				this.actionName="move";
			}
			else
			{
				this.actionName="stand";
			}
		}
		
		/**
		 *设定当前的行动目标 
		 * @param actTarget
		 * 
		 */		
		public function setActTarget(actTarget:MapTarget):void
		{
//			if(actTarget)														
//				actTarget.isSelect	=	true;
			
			if( this.linkAction.setActHandler(actTarget))return;
			
			
			if(this.infectionState || this.actionLocked || !actTarget.actionEnabled){return;}
			this.actionInterrupt();
			this.actTarget=actTarget;
			
			var targetPoint:Point=this.actTarget.mapGrid.coordinatePoint;
			
			this.findingTo(targetPoint);
		}
		
		/**
		 *设定当前的移动目标 
		 * @param point
		 * 
		 */		
		public function setMove(point:Point):void
		{
			this.linkAction.cleanTargets();		//清空所能行动目标
			
			if(this.actionLocked)return;
			this.actionInterrupt();
			this.findingTo(point);
			
			
		}
		
		/**
		 *获得下一个移动方案 
		 * 
		 */		
		
		public function nextMove():void
		{
			if(!this.nowMoveAry.length)
			{
				if(!this.findingAry.length && this.actTarget)
				{
					this.findingTo(this.actTarget.mapGrid.coordinatePoint);
				}
				if(this.findingAry.length)
				{
					var nextFindingPoint:Point=this.findingAry.shift();
					this.nowMoveAry=GV_Map.instance.getPointsAryBetweenTwoPoints(this.mapGrid.coordinatePoint,nextFindingPoint);
				}
			}
			if(this.nowMoveAry.length)
			{
				var nextPoint:Point=this.nowMoveAry.shift();
				if(this.cureState && !GV_Map.instance.getCoordinateGrid(nextPoint).isHaven)
				{
					VP_errorPanel.instance.setErrorMessage(Language.CureNotToHavenNot);
					VP_errorPanel.instance.enterFrame();
					GU_Sound.instance.playCommSound("System_Prompt");
				}
				else
				{
					this.beginMoveTo(GV_Map.instance.getCoordinateGrid(nextPoint));
					return;
				}
			}
			this.actionInterrupt();
		}
		
		/**
		 *行为中断 
		 * 
		 */		
		public function actionInterrupt():void
		{
			this.playNowState();
			this.findingAry=new Array;
			this.nowMoveAry=new Array;
			
			this.actTarget=null;
			
		}
		
		/**
		 *开始治愈自己 
		 * 
		 */		
		private function beginCure():void
		{
			this.cureCount=0;
			this.cureState=true;
			
			if(GD_Player.instance.noNew)
				this.setState(10002002,true)//,0,"zhiliao");			//特效
		}
		
		/**
		 *完成治愈自己 
		 * 
		 */		
		public function finishCure():void
		{
			this.cureState=false;
			if(this.infectionState){
				GU_Sound.instance.playCommSound("Body_heal");	
				this.turnToHunman();
			}
			this.setState(10002002,false);			//特效
		}
		
		/**
		 *向目标点寻径移动 
		 * @param pt 目标点
		 * 
		 */		
		public function findingTo(pt:Point):void
		{
			this.findingAry=GU_BarPathFinding.getPolicyPointsAry(this.mapGrid.coordinatePoint,pt,GV_Map.instance,this.actTarget);
			if(null==this.findingAry || this.findingAry.length<1)
			{
				if(this.characterData.characterState==3)
				{
					//掉落奖励  
					GD_AllFriends.instance.playFriendOver(this.characterData);
					return;
				}
				
				if(GV_Map.instance.buildMode==GV_Map.CANNOTBUILDMODE){
					VP_errorPanel.instance.setErrorMessage(Language.notReachHere);
					VP_errorPanel.instance.enterFrame();
					GU_Sound.instance.playCommSound("System_Prompt");
				}
				return;
			}
			this.nowMoveAry=new Array;
			
			if(!this.moveDir)
			{
				this.nextStep();
			}
		}
		
		public function reset():void
		{
			
		}
		
		override public function setPosition(mapGrid:GD_MapGrid):void
		{
			super.setPosition(mapGrid);
			this.actionInterrupt();
		}
		
		override public function release():void
		{
			this.removeListener();
			super.release();
			this.cleanAllObserves();
			if(this.paperMan){this.paperMan.release();}
			this._paperMan=null;
		}
		
		
		/**
		 *覆写碰撞检测 
		 * @param checkX
		 * @param checkY
		 * @return 
		 * 
		 */		
		override public function hitTestPointCheck(checkX:Number, checkY:Number):Boolean
		{
			if(null==this.paperMan)return false;
			if(super.hitTestPointCheck(checkX,checkY))
			{			
//				var checkTarget:MovieClip_BMP=paperMan.getChildAt(0) as MovieClip_BMP;
//				if(checkTarget==null)return false;
//				var bmp1:BitmapData = new BitmapData(checkTarget.width,checkTarget.height,true,0);
//				bmp1.draw(checkTarget);
//				
//				return bmp1.getPixel32(checkTarget.mouseX,checkTarget.mouseY)==0?false:true;
				return this._paperMan.hitTest(new Point(checkX,checkY));
			}
			return false;
		}
		
		/**update by jamesge 2012年6月4日*/
		public function cleanAllObserves():void
		{
			if(null==characterData)return;
			this.characterData.removeObserver("weaponchange",this);
			this.characterData.removeObserver("life",this);
			this.characterData.removeObserver("weaponchange",this);
			this.characterData.removeObserver("palySpeed",this);
			this.characterData.removeObserver("friendAct",this);
			
		}
		/**update by jamesge 2012年6月4日*/
		
		/*getter & setter*/
		public function get findingAry():Array
		{
			return _findingAry;
		}
		
		public function get nowMoveAry():Array
		{
			return _nowMoveAry;
		}
		
		public function set nowMoveAry(value:Array):void
		{
			_nowMoveAry = value;
		}
		
		public static function get instance():MMT_Character
		{
			return _instance;
		}
		
		public function set findingAry(value:Array):void
		{
			_findingAry = value;
		}
		
		/**
		 *可否被追击 
		 * @return 
		 * 
		 */		
		public function get chaseEnabled():Boolean
		{
			if(this.mapGrid.isWall)return false;
			if(this.mapGrid.isHaven)return false;
			if(this.infectionState)return false;
			return true;
		}
		
		/**
		 *可否被攻击 
		 * @return 
		 * 
		 */		
		public function get attEnabled():Boolean
		{
			if(this.infectionState || this.beHittedCoolDown || this.actionLocked)return false;
			return true;
		}
		
		public function get actTarget():MapTarget
		{
			return _actTarget;
		}
		
		public function set actTarget(value:MapTarget):void
		{
			if(_actTarget)_actTarget.isSelect=false;
			_actTarget = value;
			if(_actTarget)_actTarget.isSelect=true;
		}
		
		public function get paperMan():VCT_PaperMan
		{
			return _paperMan;
		}
		
		override public function set moveDir(value:int):void
		{
			super.moveDir=value;
			this.playNowState();
		}
		
		public function get faceDir():int
		{
			return _faceDir;
		}
		
		public function set faceDir(value:int):void
		{
			_faceDir = value;
		}
		
		public function get actionName():String
		{
			return _actionName;
		}
		
		public function set actionName(value:String):void
		{
			_actionName = value;
		}
		
		public function get beHittedCoolDown():int
		{
			return _beHittedCoolDown;
		}
		
		public function set beHittedCoolDown(value:int):void
		{
			_beHittedCoolDown = value;
		}
		
		override public function set mapGrid(value:GD_MapGrid):void
		{
			if(this.mapGrid)this.mapGrid.isCharacter=false;
			super.mapGrid=value;
			if(this.mapGrid)
			{
				this.mapGrid.isCharacter=true;
				var isControlCharater:Boolean=(this==GV_Map.instance.controlTarget as MMT_Character);
				if(!this.cureState && this.characterData.life<this.characterData.lifeMax && this.mapGrid.isHaven)
				{
					this.beginCure();
				}
				if((this.mapGrid.isHaven || this.mapGrid.isWall) && isControlCharater && GU_dealBgSound.instance.turnMusicByCharacter!=2)
				{
					GU_dealBgSound.instance.turnMusicByCharacter=0;
				}
				if(!this.mapGrid.isHaven && !this.mapGrid.isWall && isControlCharater)
				{
					if(GU_dealBgSound.instance.turnMusicByCharacter!=2)
					{
						GU_dealBgSound.instance.turnMusicByCharacter=1;
					}
				}
			}
		}
		
		public function get isControl():Boolean
		{
			return _isControl;
		}
		
		public function set isControl(value:Boolean):void
		{
			_isControl = value;
			if(this.isControl)
			{
				this.mouseEnabled=false;
				this.mouseChildren=false;
			}
			else
			{
				this.mouseEnabled=true;
				this.mouseChildren=true;
			}
		}
		
		public function get infectionState():Boolean
		{
			return _infectionState;
		}
		
		public function set infectionState(value:Boolean):void
		{
			_infectionState = value;
			if(value)
			{
				oldSpeed=this.speed;
			}
			speed=this.infectionState?(oldSpeed/2):oldSpeed;
		}
		
		
		private var oldSpeed:int;
		override public function get speed():int
		{
			return _speed;
		}
		
		private var _speed:int;
		override public function set speed(value:int):void
		{
			super.speed=value;
			_speed = value;
			if(this.speed>MAXSPEED)this.speed=MAXSPEED;
		}
		
		private function showPlaySpeed():void
		{
			//			this.speed=this.characterData.playSpeed;
			//因为所以的人的速度都一样
			this.speed=GD_Player.instance.speed;
			this.oldSpeed=GD_Player.instance.speed;
		}
		
		public function get lifeBar():Sprite
		{
			return _lifeBar;
		}
		
		/**
		 * 当前治疗状态 false:不在治疗期 true:治疗期 
		 * @return 
		 */		
		public function get cureState():Boolean
		{
			return _cureState;
		}
		
		public function set cureState(value:Boolean):void
		{
			_cureState = value;
		}
		
		public function get characterData():GD_Character
		{
			return this.gameData as GD_Character;
		}
		
		public function get cureCount():int
		{
			return _cureCount;
		}
		
		public function set cureCount(value:int):void
		{
			_cureCount = value;
		}
		
		public function get cureRound():int
		{
			return this.infectionState?CUREROUND*2:CUREROUND;
		}
		
		override public function get correctPositionConditionsAry():Array
		{
			return ["没有NPC","没有建筑"]
		}
		
		override public function get resetPositionConditionsAry():Array
		{
			return ["避难所内","没有NPC","没有建筑"]
		}
		
		
		/**
		 *覆写选择优先级 
		 * @return 
		 * 
		 */
		override public function get selectPriority():int
		{
			return 29;
		}
		
		
	}
}